package com.boge.modules.music.service.impl;

import com.boge.modules.music.entity.MusictypeEntity;
import com.boge.modules.music.service.MusictypeService;
import com.boge.modules.sys.controller.WebController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boge.common.utils.PageUtils;
import com.boge.common.utils.Query;

import com.boge.modules.music.dao.MusicDao;
import com.boge.modules.music.entity.MusicEntity;
import com.boge.modules.music.service.MusicService;


@Service("musicService")
public class MusicServiceImpl extends ServiceImpl<MusicDao, MusicEntity> implements MusicService {

    @Autowired
    private MusictypeService musictypeService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<MusicEntity> page = this.page(
                new Query<MusicEntity>().getPage(params),
                new QueryWrapper<MusicEntity>()
        );

        List<MusicEntity> records = page.getRecords();
        if(records != null && records .size() > 0){
            for (MusicEntity record : records) {
                Integer typeId = record.getTypeId();
                MusictypeEntity entity = musictypeService.getById(typeId);
                record.setTypeName(entity.getName());
                String img = record.getImg();
                if(!img.contains("http://")){
                    record.setImg(WebController.BASE_URL+record.getImg());
                }
                String musicUrl = record.getMusicUrl();
                if(!img.contains("http://")){
                    record.setMusicUrl(WebController.BASE_URL+record.getMusicUrl());
                }
            }
        }

        return new PageUtils(page);
    }

}